package thread;

public class ThreadDemo1{
    public static void main(String[] args) {
        //new Thread(){}: 定义了一个没有名字的类，同时还创建了一个对象(用t1变量表示)。 这个匿名类继承了Thread类。
        Thread t1=new Thread(){
            public void run() {
                for (int i = 1; i < 100; i++) {
                    System.out.println(i);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        t1.start();


    }

    /*public static void main(String[] args) {
        //2.创建对象，调用start()
        Thread1 t1 = new Thread1();
        t1.start();
    }*/
}

//1.继承Thread，重写run方法
/*
class Thread1 extends  Thread{
    public void run() {
        for (int i = 1; i < 100; i++) {
            System.out.println(i);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
*/

